package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.PurchaseReceiptDetail;
import com.pureut.storage.dto.PurchaseReceiptDetailDto;
import com.pureut.storage.mapper.PurchaseReceiptDetailMapper;
import com.pureut.storage.service.PurchaseReceiptDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/***
 *
 * Author:C
 * Date:2023/01/17 11:11
 * @DESC
 */
@Service
public class PurchaseReceiptDetailServiceImpl extends ServiceImpl<PurchaseReceiptDetailMapper, PurchaseReceiptDetail> implements PurchaseReceiptDetailService {

    @Resource
    PurchaseReceiptDetailMapper purchaseReceiptDetailMapper;


    /**
     * 采购入库明细列表
     * @param id
     * @return
     */
    @Override
    public List<PurchaseReceiptDetailDto> getReceiptDetail(long id) {

        List<SysDictData> statusArray = DictUtils.getDictCache("purchase_receipt_detail_status");
        Map<String, String> detailStatusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<PurchaseReceiptDetailDto> detailById = purchaseReceiptDetailMapper.getDetailById(id);
        for (PurchaseReceiptDetailDto entity : detailById) {
            entity.setStatusDict(detailStatusMap.get(entity.getStatus()));
        }
        return detailById;
    }
}
